<script setup>
import { ref, computed } from 'vue';
import { useRoute, useRouter } from 'vue-router';

const route = useRoute();
const router = useRouter();

const images = [
  { id: 1, src: new URL('../img/1.png', import.meta.url).href, title: '图片1' },
  { id: 2, src: new URL('../img/2.png', import.meta.url).href, title: '图片2' }
];

const currentImage = computed(() => {
  return images.find(img => img.id === parseInt(route.params.id));
});

const goBack = () => {
  router.push('/gallery');
};
</script>

<template>
  <div class="detail-container">
    <button class="back-button" @click="goBack">返回</button>
    <div v-if="currentImage" class="image-detail">
      <img :src="currentImage.src" :alt="currentImage.title">
      <h2>{{ currentImage.title }}</h2>
    </div>
  </div>
</template>

<style scoped>
.detail-container {
  padding: 2rem;
  max-width: 1200px;
  margin: 0 auto;
}

.back-button {
  margin-bottom: 1rem;
  padding: 0.5rem 1rem;
  background-color: #1877f2;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.back-button:hover {
  background-color: #166fe5;
}

.image-detail {
  text-align: center;
}

.image-detail img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

.image-detail h2 {
  margin-top: 1rem;
}
</style>